package com.wry.spring.proxy;

/**
 * <h1> 静态代理 </h1>
 *
 * @author wry
 * @since 2025.04.04
 */
public class StaticProxy {

    public static void main(String[] args) {
        // 原始对象
        TrainStation trainStation = new TrainStation();
        // 代理对象
        Proxy proxy = new Proxy(trainStation);
        // 用户来买票-找中介代买
        proxy.issueTickets();
    }

    /**
     * 车站买票
     */
    interface BuyTickets {

        void issueTickets();
    }

    /**
     * 车站  被代理对象
     */
    static class TrainStation implements BuyTickets{

        @Override
        public void issueTickets() {
            System.out.println("我是车站-出票完成！");
        }
    }

    /**
     * 中介-代理对象（车站）
     */
    static class Proxy implements BuyTickets{

        private TrainStation trainStation;

        public Proxy(TrainStation trainStation) {
            this.trainStation = trainStation;
        }

        // 方法增强
        @Override
        public void issueTickets() {
            System.out.println("我是代理-询问使用车票吗？");
            System.out.println("我是代理-还有余票啊！");
            trainStation.issueTickets();
            System.out.println("我是代理-帮你买到车票啦！");
        }
    }
}
